<button> with JSF 1.2 - jsf

Simple question:
Is there any way of rendering a html <button>-element using JSF or any other framework (RichFaces, Tomahawk etc.)? Or would I have resort to writing a custom component for this?

No, there isn't. Since a <button> is usually only used in GET requests, you can also just put it plain vanilla in the JSF template. You don't need to bind any action to a JSF managed bean anyway.
In JSF 2.0, there's by the way the <h:button> which renders a GET button and offers the option to include view parameters and/or to perform implicit navigation. Both features aren't available in JSF 1.2, so there's not really a point of having similar component in JSF 1.2 anyway.
On the other hand, if you actually intend to use a <button> to invoke a POST managed bean action method, then you should really be using a <h:commandButton> instead. If you're having a specific problem with it for which you thought that using <button> was the solution, then you'd need to reframe your question to elaborate in more detail about that specific problem so that we can answer how to achieve the same with <h:commandButton>.

Related

What is an alternative of a4j:JsFunction in JSF 2.0?

I am new to JSF 2.0.
My current project is build on JSF 1.3 and Richfaces 3.3.
We are trying to migrate to JSF 2.0.
There is limitation to not use Richface 3.3 or 4.0 in Current Project or any third party tool/library. Our goal is to only use JSF 2.0 functionality/feature.
In my project there is lot of use of
<a4j:jsFunction data="action" oncomplete="JavaScriptFunction(data); >
<a4j:actionaram name="nm" assignTo="#beanName.methodName"> </a4j:actionparam>
</a4j:jsFunction>
I want to remove this type of a4j:jsFunction with h:commandButton or
any jsf 2.0 standard mechanism.
I am not able to find out best way to call Bean function which return some value and assign this return value to JavaScript function.
JSF 1.3? I thought 1.2 was the latest?
On to your question. The idea to only use JSF 2.x is invalid and you should have the decision maker reconsider because skimping on OmniFaces will impede your productivity and the general code quality.
The way I see it you have three choices:
OmniFaces
Click button with display:none using javascript. Said button can have f:ajax as a child
Rip o:commandScript http://showcase.omnifaces.org/components/commandScript it's open source.
I can fully understand that a company today says no to Primefaces or Richfaces and honestly I would recommend it for many applications. Omnifaces however is to be seen as a proper for JSF.

PrimeFaces - Set a JSF component as mandatory

I am using PrimeFaces and JSF - I need to be able to set a component on the page as mandatory in response to an AJAX event. Is the best way to accomplish this using the following code or is there also a way to accomplish it using JQuery ?
Thanks
UIInput componentToChange = (UIInput) facesContext.getViewRoot().findComponent("ComponentId");
componentToChange.setRequired(true);
Thanks
Just set the component's required attribute with the desired EL expression.
E.g.
<h:inputText ... required="#{bean.required}" />
There are even EL ways without needing an additional bean property, but it's impossible to propose one based on the sparse information provided so far.
Use findComponent() with care. Think twice if it really can't be done just in the view (XHTML) side.

Iterating over a list in JSF 1.2

Is there any way of iterating over a list in JSF 1.2 without using any third party components? I know I can do it using Tomahawk. I also know that it can be done using JSTL, but I am keeping that as my last resort. Also I cannot use <ui:repeat> since we are using JSF 1.2. Is there any elegant way like <ui:repeat> to do it in jsf 1.2?
The only JSF 1.2 component which can iterate over a List is the <h:dataTable>.
In JSP, the only other "standard" (i.e. not "3rd party") tag which can iterate over a List is the JSTL <c:forEach>. Using JSTL shouldn't harm that much if the List which you'd like to iterate over is already available during view build time. You'll only run into trouble when it's only available during view render time, for example because it's been nested in a <h:dataTable> and should be iterating over a property of table's var. This just won't work due to reasons also mentioned in JSTL in JSF2 Facelets... makes sense?
There are no other ways without using a 3rd party library such as Tomahawk's <t:dataList>, unless you're open to reinventing the wheel by creating a custom UIComponent yourself. This is however not a trivial job.
It's however possible to integrate Facelets 1.x in JSF 1.2. A guide is described in the Facelets 1.x docbook. This is only going to be quite some of work if you already have an existing JSF application using JSP as view technology; you'd need to convert JSP to Facelets. But it'll in end make the upgrade path to JSF 2.x so much easier. See also a.o. Migrating from JSF 1.2 to JSF 2.0 and Why Facelets is preferred over JSP as the view definition language from JSF2.0 onwards?

Can I use <f:setPropertyActionListener> inside an autoComplete component?

Can I use <f:setPropertyActionListener> inside an autoComplete component?
The autoComplete uses the managedbean mbAC for example and I want to send the cliCod from it to another bean with:
<f:setPropertyActionListener target="#{targetBean.cliCod}" value="#{mbAC}" />
Is <f:setPropertyActionListener> the right way to do this?
The <f:setPropertyActionListener> works only inside a component implementing ActionSource interface, such as <h:commandButton>, <h:commandLink>. It's unclear what autocomplete component you're talking about, but the PrimeFaces <p:autoComplete> doesn't implement it.
You need to look for an alternate solution, such as placing the bean in the right scope and/or using #ManagedProperty and/or using <p:ajax> instead. The exact solution depends on the concrete functional requirement which you didn't tell anything about.
In the future questions it would be more helpful for us and yourself if you ask how to achieve the given functional requirement instead of asking how to achieve a solution of which you thought that it's the right solution but which after all isn't.

JSF and PrimeFaces Strategy

What is or could be a best practice?
Using standard JSF components and combine them by PrimeFaces components when needed (for example when DHTML or AJAX components are needed)
Forget all JSF Components and try to use all PrimeFaces components as much as possible
Please explain it and tell me about your experiences.
Thanks in advance...
PrimeFaces is your AJAX framework, so if you need to send ajaxical request, then use PrimeFaces components.
Even though, you dont need to send ajax request, but you can still use PF component, if u need to provide a consistency look for your web page. For example, h:commandButton and p:commandButton. Use p:commandButton if u need to send ajax request, but u can also do this
<p:commandButton ajax="false" action="Your Action here"/>
This will provide the same result as:
<h:commandButton action="Your Action here"/>
but this way, you can provide the same consistent look for your button throughout the page.
PrimeFaces does not have replacements for h:panelGrid, h:panelGroup, h:inputText, h:outputText ...
Depends on the sole functional requirement. If you're already using PrimeFaces and whatever you want to achieve can better/easier be achieved using a PrimeFaces component, use it.
Option 1 comes close, but option 2 goes overboard. PrimeFaces for example doesn't have a <p:form>, <p:panelGroup>, <p:outputText> or something.
With Primefaces it's very easy to get a consistent look for your application since it comes with Themeroller CSS framework. And you can easily switch designs. Although it is not difficult to let plain jsf components look like primefaces components if you apply the right css classes.
I think primefaces is a great component library. However some components are still buggy (e.g. date picker). So if you get some unexpected behavior with a primefaces component, it is alway good to have a jsf fallback (or an alternative from another component library or from jquery).
I have no experience with mixing different component libraries. Would be interesting to know, how they interact. But that would be subject of another question ...

Resources