Passing a value to bean in commandButton in JSF 1.2 - jsf-1.2

How can I pass a variable to the managed bean using h:commandButton in JSF 1.2. We are having <f:param> and <f:attribute> which works in JSF 2. Is there any similar way like that in JSF 1.2 to pass value.
Thank You.

You can use f:setPropertyActionListener for that:
<h:commandButton style="display: none;"
action="#{chAction.selectClient}" immediate="true">
<f:setPropertyActionListener target="#{chAction.selectedClientId}"
value="#{res.clientId}" />
</h:commandButton>

Related

Spring MVC: Does <Form:Label> really solves any additional purpose or is it okay to use HTML label tag?

Does Form:Label class and path solves any purpose?
<form:label class="boldText" path="comments.commentOnChild">
<spring:message code="label.commentOnChild" />
</form:label>
What if we write statement simply in -label- tag? What additional benefits does form:label provides over HTML Label? What if i do not use Form:Label at all?
As we know that <form:label /> tag is associated to spring so it will have access to the model and binding results also and it can use another css class in case of any error.
<form:label cssClass="title" cssErrorClass="title error" path="student" />
In case of error this code will render differently than the normal label.You could also do this with normal tag but for that you need to include some logic into your pages, which will be extra you will be doing.
The <form:label /> tag has access to the underlying model and binding results through path variable and as such can, on error, use another style class.
The <spring:message /> tag provides you with internationalization support using Spring's MessageSource concept. The MessageSource is an interface providing functionality for retrieving messages. It closely resembles JSTL's fmt:message-tag, however, the MessageSource classes can be integrated with the Spring context. Also, the <spring:message /> tag, works with the locale support that comes with Spring.
Also you can do this without the form tag but that would mean you need to include some logic into your pages but it isn't advisable.

CSS not rendering correctly after ajax update using <ui:repeat>

this one is kind of complicated. Basically I am using Material Design Lite css by google and firing an ajax request to add input fields dynamically using primefaces.
<h:commandLink value="+ Add something>
<f:ajax listener="#{bean.method()}"
execute="#form"
process="#form"
render="#form" />
</h:commandLink>
The method called adds a new div in ui:repeat by adding a new entry to a list in my bean.
<h:form>
<ui:repeat value="#{bean.list}" var="v">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<h:inputText value="#{v.value}" id="valuetitle"/>
<label class="mdl-textfield__label" for="valuetitle">valuetitle</label>
</div>
</ui:repeat>
</h:form>
Problem: The CSS is not getting updated properly. It does not initiate the class I gave to the div.. any one knows a solution?
Some months ago I had this very same problem. This situation happens because MDL applies their style only once, during the rendering of the HTML.
To fix it you must explicitly ask MDL to re-render the view to reapply the styles. To do this you must call the following MDL function on the success status of the AJAX request:
componentHandler.upgradeAllRegistered()
Your code should look like this:
<h:commandLink value="+ Add something>
<f:ajax listener="#{bean.method()}"
execute="#form"
process="#form"
render="#form"
onevent="function(data){if (data.status === 'success'){componentHandler.upgradeAllRegistered();}}"/>
</h:commandLink>
You can later better encapsulate this solution for a more clean approach, but for now this can solve your problem.
For more info about this situation you can check this issue on the MDL's GitHub page.

How to render a template page by calling its method from TAL portlet(##manage-portlets)

How do I call a method which is in the filesystem from a TAL Portlet (made available by collective.portlet.tal)?
This is how I did it: I defined a new BrowserView (createPictMenu.py in my case) and then registered it as the renderer for a new portlet component:
class AddressTAL(BrowserView)
def my_address()
address_bar = ViewTemplatePageFile('templates/address_left.pt') # this
is the page template I want for my new portlet.
And in configure.zcml:
<plone:portlet
name="collective.portlet.tal.TALPortlet"
interface="collective.portlet.tal.talportlet.ITALPortlet"
assignment="collective.portlet.tal.talportlet.Assignment"
view_permission="zope2.View"
edit_permission="cmf.ManagePortal"
renderer=".browser.createPictMenu.AddressTAL"
addview="collective.portlet.tal.talportlet.AddForm"
editview="collective.portlet.tal.talportlet.EditForm"
/>
Then I went to localhost:8080/myproject/##manage-portlets and selected the TAL Portlet option from the Add Portlet dropdown list. I informed title as address and for description I inserted the snippet below to call address_tal():
<span tal:define="global li view/myaddress">
<span tal:replace="structure li" />
</span>
Unfortunately, it didn't work. Please help.
You should have registered your class AddressTAL with a browser:view directive, not a plone:portlet one. Like this:
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser">
<browser:page
name="address-view"
class=".browser.createPictMenu.AddressTAL"
for="*"
permission="zope2.View"
/>
</configure>
And then call it with:
<div tal:define="my_address python:context.restrictedTraverse('##address-view').my_address()" >
Your method returns <span tal:content="my_address" />
</div>
Or:
<div tal:define="address_view context/##address-view" >
Your method returns <span tal:content="address_view/my_address" />
</div>
It's of very little information or matter that the method is on the file system. That's where it should be. Having it in the ZODB is possible but a bad idea.
But there are many types of methods, and how you call them from TAL differs.
You can have what in the ZMI is called "Script (Python) methods" that are accessed through portal_skins, you can have methods on content objects and you can have methods on views. These are all callable from TAL.
For methods that are neither of these, you will have to create a method of the above type that you can call, which in turn then calls the method you want to call. For a portlet the obvious place to create that method is by adding a method on the Renderer, which is a type of view, and which you can call from the portlets template.
In your case, the method you want to call is a method on the renderer already. That means you just call it.
<p tal:content="view/myaddress" />
Note that you have forgotten the self parameter in the definition. Also, please follow PEP8.

Injection From Pages.xml (Seam)

Does anyone know if I can inject value from pages.xml into a Seam component? In pages.xml there seems to be an in element that would indicate I can but I can't figure out how to use it & documentation is lacking.
I'm trying to set a value in a component that varies from page to page. It needs to be set for page load & I don't want it exposed to the user. Here's what I've tried at the moment:
<page view-id="/daily.xhtml">
<in name="chartLoader.reportType" value="DAILY"/>
<action execute="#{chartLoader.loadData}" />
</page>
<page view-id="/hourly.xhtml">
<in name="#{chartLoader.reportType}" value="HOURLY"/>
<action execute="#{chartLoader.loadData}" />
</page>
Neither of these work now with an error of:
javax.el.PropertyNotWritableException: Illegal Syntax for Set Operation
The reportType property is private but it has the correct public setter method. So I'm thinking that my syntax is slightly off.
Does anyone know how to use this element correctly or have a better suggestion?
Thanks,
Lee
Try this instead
<action execute="#{chartLoader.setReportType('DAILY')}"/>

Auto Select Option Tag by default in Spring MVC

Does anybody have an idea on how to auto select option tag?
I checked at the spring form tag library but cant see any property related to an option value being selected by default when the JSP is rendered.
I basically have this:
<p>
<label for="plantLabel" class="label">Plant:</label>
<form:select path="strPlant" >
<form:option value="-" label="--Select Please--" />
<form:options items="${plants}" itemLabel="strPlant"
itemValue="strPlant" />
</form:select>
</p>
and, I want an option from the list (ie. items="${plants}" , say 'NeemTree') to be shown as already selected when the page loades.
Thanks
The "selected Option" will be calculate by Spring MVC based on the path="" attribute.
In above case I think,
Either the value of path="strPlant" is null
OR
the array/collection/map represented by items="${plants}" attribute does not contain an element corresponding to path="strPlant" value.
e.g.
if path="strPlant" results in String NeemTree, items="" must have NeemTree as element.
itemLabel="strPlant" and itemValue="strPlant" make sense only if you are passing an instance of HashMap to items="" attribute.
Spring Reference Documentation

Resources