RichFaces: TabPanel and param - java

Currently, i am dealing with rich:tabPanel in my web application based on JSF 2.0.
I encounter a very strange problem, which is related to my richface component.
Basically, i print some same stuff on each panel (here, it is a schedule table of a show, tab contains the day and content of tab contains the differents hours ).
Consequently, i have something like that:
<rich:tabPanel>
<c:forEach items="#{show}" var="hour" ...>
<rich:tab>
<a4j:commandLink ...>
<a4j:param value="hour.something" assignTo="#{bean.method}" />
</a4j:commandLink>
</ ..... >
When i click on the first commandlink, when my webpage is displayed, it's ok. But when i choose an other tab, and i click on the commandlink, the "bean.method" is not call. I need to click a second time to make the call of the function.
Finally, when i put the tabPanel as "switchtype=server", it works very well (without clicking 2 times).
But that's not the purpose, i want to use the client mode.
I see that on JIRA of richfaces v3, this problem has been solved JIRA JBoss. But there is no more information (except a comment but it's not working).
If anyone can help, it would be great.
Regards,

The problem is you are using nested forms(form within form). This is not recommended in JSF. Even in HTML it is invalid. Remove one form and it will work.
Read this post too.

Related

JSP drop down list to select first option by default on page load using struts

Hope someone can help me out on this.
I've got the following drop down list in JSP:
<html:select styleId="facilityId" property="facilityId">
<html:options collection="<%=Session.CONSUMER_FACILITY%>"
property="id" labelProperty="facilityDescription"
/>
</html:select>
That gets a collection of list to be displayed in the drop down from the Java class perfectly.
But now when I open the page where it shows the drop down list, how can I make the first option selected by default on page load, without clicking and selecting a option?
Can I do something inside that JSP code or some Javascript that can do that?
I'm using Struts.
Hope this makes sense what i'm looking for.
Set facilityId value to expected default during ActionForm initialization.
Guess you're using Struts 1.x

Previous Page URL JSF

I'm working with a JSF application and I'm seeing the URL that appears in the browser's navigation bar is always for the page I just left, rather than the page I'm on.
It is because you are forwarded(not redirected) to another page from server, To redirect you need to set the following param with your return
?faces-redirect=true
That will happen if you're using POST for navigation by e.g. commandlinks/commandbuttons. If it's pure page-to-page navigation and you actually don't need to submit anything to the server, then you've a bigger problem. You will indeed get exactly this nasty "side effect" and your links will not be bookmarkable nor searchbot-crawlable. PRG (Post-Redirect-Get), as suggested by other answers, will indeed solve the bookmarkability ("one URL behind") problem, but it surely won't solve the inability of searchbots to crawl/index the pages.
Just don't use POST for plain page-to-page navigation in first place. Use GET for that. Use <h:link> instead of <h:commandLink> and so on. In code, replace all
<h:form>
<h:commandLink value="Next page" action="nextpage" />
</h:form>
by
<h:link value="Next page" outcome="nextpage" />
See also:
When should I use h:outputLink instead of h:commandLink?
What is the difference between redirect and navigation/forward and when to use what?
By default, JSF performs POST operations directed to the original page's URL. If you use a <navigation-rule>, you can specify <redirect/> to let the browser perform an additional request, so the target page's URL will appear in the navigation bar.

Richfaces: Link-like text with ContextMenu

I want to render using Richfaces a context menu on left click on a link-appearing text (blue text, and underline and cursor onmouseover). So, imagine a link which when clicked shows a context menu. Note that I don't care if the text is indeed a link, I just want it to appear as a link. So, even normal text would be fine, I would make it appear as a link using CSS.
I have the following conditions:
The context menu must appear on client side, without making a request.
The context menu must appear using a rich:componentControl (these "links") are inside a datatable, so the same rich:contextMenu must be re-used.
I still have not found a satisfactory solution, as each approach I have tried has caused a problem for me:
If I use h:outputText (that would be ideal), I cannot attach on it a rich:componentControl (I guess because it cannot fire an onclick event).
If I use a4j:commandLink, although I can attach a rich:componentControl, it makes a server request. I tried to add onclick="return false;" to prevent the request, but Richfaces adds the JS generated by the rich:componentControl after whatever is inside the onclick, which causes this code not to be reached at all, and of course the context menu not to appear at all.
Is there any way to do this? Please remember, no request!
You may try
<rich:componentControl disableDefault="true" ...>
According to documentation with this param componentControl should add return false; itself.
But be aware of corresponding bug: RF-5607
In case documentation lies you may use html anchors. This answer shows how to create a link with componentControl and without page refresh:
<h:outputLink value="#" id="link" onclick="return false;">
<h:outputText value="Link text"/>
<rich:componentControl attachTo="link" for="panel" operation="show" event="onclick"/>
</h:outputLink>
The onclick="return false;" prevents the anchor from scrolling the page to the clicked link.

Enter Key Press behave like Submit in JSF

How to make Enter Key Press behave like Submit in JSF. It works with InputBoxes; but not with inputSecret boxes
I haven't seen this issue before. The chance is little that this behaviour is browser specific. Try in different kinds of browsers to exclude the one and other (IE6/7/8, FF, Safari, Chrome, etc). The chance is bigger that this is caused by a (poor) Javascript key event listener which incorrectly suppresses the enter key (for example a JS password validator which checks the entered characters).
If still in vain, just add the following onkeypress to the h:form:
<h:form onkeypress="if (event.keyCode == 13) this.submit();">
You need to take textareas into account however. If you have them, then you need to copy all onkeypress events over the h:inputXXX elements expect of textareas yourself.
If you want to press ENTER key instead of submit in any form, what we have to do here is add defaultcommand attribute in af:form tag and give id of the submit button as value. Sample code snippet for this is
<af:form id="f1" defaultCommand="cb1">
<af:outputText value="User Name" id="usename"/>
<af:inputText value="#{BackingBean.userName}" id="uname" />
<af:outputText value="Password" id="pword"/>
<af:inputText value="#{BackingBean.password}" id="paword" secret="true"/>
<af:commandButton text="Submit" action="#{BackingBean.method}" id="cb1" />
</af:form>
I made it work by placing an additional inputBox and hiding it using javascript. Let me know if you have any other suggestions
Thanks baluC for pointing me in the right direction
Jerry
tested with jsf 2. put:
<h:commandButton id="hidden" style="visibility: hidden;" action="#{mybean.myaction()}" />
in your form
From ComputerPilot's answer I came to know that it's bug in IE which wouldn't make the parent form to submit if there's only one input element. To overcome this problem I added one more input Box with attribute style="display:none" and it worked fine.
There is an old specification that pops into my mind with this one. If you have a form that contains just one input field, the behaviour of submitting on the enter-key doesn't work in some versions of Internet Explorer. The easiest fix is to make sure you have more than one input field.
Other reasons for this problem include...
Not having an input of type submit
Having an input of type submit, but it isn't visible on the page (hidden or positioned off-page)
This behaviour is very specific to this browser.
MS Bug Report Here: connect.microsoft.com: submit button value not posted with form submission

Struts 2 and locale question

I've got forms that I display on almost every pages of a website (a login form, for example), so I don't use an action for those. The "post" of those forms just goes to an action and if there is a validation error, it displays another "central" page. The only thing that doesn't seems to work in the form page is displaying a message in different languages using the tag <s:text>
It always use the default locale defined in struts.properties. I guess it's because I don't call any action before displaying the form.
Anyway, I have 2 files : struts_fr.properties and struts_en.properties
In struts.properties I have
struts.locale = fr_CA
And I use something like :
<s:text name="login.label.username" />
The message displayed is always the one from the "struts_fr.properties".
The question is : How can I set the locale for struts, before using the s:text tag, when there is no action called?
Well it seems that it worked "alone" after a while... maybe the work directory was in cause here. We also have some custom interceptor so maybe that's why it worked.

Categories