tags:

views:

42

answers:

3

Hey folks,

my xhtml code:

<h:commandLink action="#{detailController.updateProject}" class="positive" >
 <h:graphicImage library="img" name="tick.png" alt=""/> 
 <h:outputText value="Save" />
</h:commandLink>

This action (updateProject()) is not being called from JSF framework! Even if I delete it in the managedBean there is no exception thrown.

Does anybodyelse has had problems like that? I can't even explain that -.- I mean this action ethod is there!


ADD: Yes it is in a h:form tag! But I have two forms in that view! May that be the problem?


ADD2: I should also mention that if I hit the button it throws me back to the previous view! So my action method is being ignored and instead it opens another view ?!?!

To provide more information, my page is built like that:

panelGroup name=show rendered=!controller.edit
  form 
    buttons
    outputtext
  /form
/panelGroup

panelGroup name=edit rendered=controller.edit
   form
     buttons
     inputText
   /form
/panelGroup

So I have both, edit and show of one entity at one file! But only the buttons in the bottom form show that strange behaviour (see above).


Answering BalusC: 1. I use two forms (they aren't nested!) 2. In the bottom form I had already placed a h:messages I'm gonna try putting my controller into viewScop for checking 3 and 4 I don't know how to check 5. Thank you for that..

+2  A: 

Just a quick question: is your <h:commandLink> nested inside a <h:form>?

If this is not the case, you must include your command link inside a form element, otherwise it will not work.

Just for code simplification, you can use the value attribute instead of adding a <h:outputText> component:

<h:commandLink action="#{detailController.updateProject}" class="positive" value="Save">
    <h:graphicImage library="img" name="tick.png" alt=""/> 
</h:commandLink>
romaintaz
+1 it is my answer too.
org.life.java
+3  A: 

This can have a lot of possible causes. @romaintaz has mentioned only the most obvious one (the most common beginner's mistake): UICommand components must be placed inside an UIForm component.

There are however more causes:

  1. You have multiple nested forms. This is illegal in HTML. The behaviour is dependent on the webbrowser used, but usually the button won't do anything. You may not nest forms, but you can use them in parallel.

  2. A validation or conversion error has occurred which is not been catched by a h:message. Normally this is logged to stdout, but you can also use h:messages to get them all.

  3. The UICommand component is been placed inside an UIData component (e.g. h:dataTable) whose value is not been preserved the right way during the subsequent request. If JSF cannot find the associated data row, the action won't be invoked. Putting bean in view scope should help a lot.

  4. The component or one of its parents has a rendered or disabled attribute which evaluated false during apply request values phase. JSF won't invoke the action then. Putting bean in view scope should help a lot.

  5. Some PhaseListener, EventListener, Filter or Servlet in the request-response chain has changed the JSF lifecycle to skip the invoke action phase or altered the request parameters so that JSF can't invoke the action.

BalusC
A: 

Unfortunately, I don't know where the mistae was. I guess it was about wrong my JSF code.

I solved this problem by simplifying my code. From that xhtml page and that one controller I made 3 xhtml-pages and 3 Controller. After refactoring all that my code looks much easier and it works now :-)

Thank you for your helpful suggestions

Sven