Adf login not working - jsf-2.2

I am using oracle adf 12.2.1.3 and I have a problem about login. When I click login button I get no action. But if I click f5 a new page appears. I could not find the problem.
login.jsff
<f:facet name="center">
<af:panelGroupLayout id="pglMain" layout="vertical" halign="center" inlineStyle="margin-left:-200px;margin-top:50px;">
<af:panelFormLayout id="pfl2" inlineStyle="margin-top: 30px;">
<af:panelFormLayout labelAlignment="start" labelWidth="150px" fieldWidth="100px" styleClass="WithColon WithVerticalSpacing"
inlineStyle="font-weight:600; margin-left: 230px;">
<af:inputText id="userId" label="Kullanıcı Adı: " value="#{viewBean.userLoginInfo.userId}" required="no" secret="false"/>
<af:inputText id="password" label="Şifre: " value="#{viewBean.userLoginInfo.password}" required="no" secret="true"/>
</af:panelFormLayout>
</af:panelFormLayout>
<af:commandImageLink icon="/img_hospitalstatement/enter.png" id="HomeCI" inlineStyle="font-size:13px"
partialSubmit="true" text="Giriş" action="#{viewBean.login}">
</af:commandImageLink>
</af:panelGroupLayout>
LoginViewBean.java
public String login () {
//ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
//ec.redirect(ec.getRequestContextPath() + "/faces/aaa/index.xhtml");
return "goToIndex";
// return null;}
login task flow
<task-flow-definition id="login-task-flow-definition">
<default-activity>login</default-activity>
<data-control-scope>
<shared />
</data-control-scope>
<managed-bean id="managed">
<managed-bean-name>indexManagedBean</managed-bean-name>
<managed-bean-class>aaa.IndexManagedBean
</managed-bean-class>
<managed-bean-scope>pageFlow</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>loginViewBean</managed-bean-name>
<managed-bean-class>xxx.LoginViewBean</managed-bean-class>
<managed-bean-scope>view</managed-bean-scope>
</managed-bean>
<task-flow-call id="xtaskflow">
<task-flow-reference>
<document>/WEB-INF/x-task-flow-definition.xml</document>
<id>x-task-flow-definition</id>
</task-flow-reference>
</task-flow-call>
<view id="login">
<page>/login/login.jsff</page>
</view>
<control-flow-rule>
<from-activity-id>login</from-activity-id>
<control-flow-case>
<from-outcome>gotoIndex</from-outcome>
<to-activity-id>xtaskflow</to-activity-id>
<redirect/>
</control-flow-case>
</control-flow-rule>
<use-page-fragments />
</task-flow-definition>
I tried redirecting and taskflow outcome but both did not work.
Note: jsf version is 2.2

try changing return "goToIndex";
to return "gotoIndex";
as your outcome is <from-outcome>gotoIndex</from-outcome>

Related

How Close PrimeFaces PhotoCam?

I'm using photocam for take picture with camera but capture option is always open. I am using photocam autostarts property with created to button which invite a method like that:
public void pcFotoStarter()
{
if (pcFoto == Boolean.FALSE)
pcFoto = Boolean.TRUE;
else
pcFoto = Boolean.FALSE;
}
This method makes my method's pcFoto field true or false , and then I defined <f:ajax execute="button" render="PhotoCam" />
According to the pcFoto Boolean Value(true or false), photocam is working or not. Problem is, photocam starts at once and I can close only 1 time photocam.Ant than I am unable to restart photocam. And my webcam usage yellow led is flashing. It's like webcam is already in usage.
try execute this Javascript code when you want to off camera
Webcam.stream.getTracks().forEach(x=> x.stop());
In my case i turn on camera while open p:photoCam in p:dialog (dynamic) and has p:ajax callback on "close" event. Like this
<p:dialog id="modalDialog" widgetVar="photoEditDialog"
modal="true" onHide="PF('photoEditDialog').toggleMaximize();"
resizable="false" closeOnEscape="true"
dynamic="true"
>
<p:ajax event="close" update="photo #this" onsuccess="Webcam.stream.getTracks().forEach(x=> x.stop());"/>
<div style="display: flex;">
<section>
<h1>Camera</h1>
<p:photoCam widgetVar="photoCam" listener="#{cc.attrs.value.onPhotoCapture}" update="preview"
width="400" height="300" photoWidth="1024" photoHeight="768"
/>
<p:commandButton type="button" value="Capture" onclick="PF('photoCam').capture()"/>
</section>
<section>
<h1>Preview</h1>
<p:graphicImage id="preview" value="#{cc.attrs.value.photo}" stream="false"/>
</section>
</div>
</p:dialog>

JSF: Datatable excecuting remove method twice

I'm facing a strange behavior in my jsf datatable component and couldn't figure out what`s going on. This is the scenario: I have a datatable with a remove button on each row. When I click on the button of the last row, it is correctly deleted. When I click on the button in the row before the last row, it deletes the row itself and also the next row. No row above it is affected.
My environment: Eclipse Neon + Tomcat 8 + Primefaces 6.0
I'm running the project from inside Eclipse.
The datasource of the p:dataTable is being modified by data selected from a p:autoComplete component.
In debbuging mode I could check that the remove method is being called multiple times with different parameters each time. Bellow is a part of the code.
It seems (looking at the browser developer tool) that the Ajax is calling the server method just once, so the multiple execution is happening at the server side.
I've already googled for similar issues in links like Link 1 and Link 2.
The page.xhtml:
<p:autoComplete id="ddl" dropdown="false"
value="#{bean.chosenItem}" var="item"
itemLabel="#{item.name}" itemValue="#{item}"
converter="convertItem"
emptyMessage="No item found" queryDelay="1000"
minQueryLength="3" autocomplete="off"
completeMethod="#{bean.findItemsCompleteText}"
forceSelection="true" placeholder="Type item name"
cache="true" widgetVar="dllWGV">
<p:ajax event="itemSelect"
listener="#{bean.addToDataTable}"
update="dtb ddl" />
</p:autoComplete>
<p:dataTable id="dtb"
value="#{bean.chosenItems}" var="rowItem"
sortBy="#{rowItem.name}" scrollable="true" scrollHeight="90"
scrollWidth="337" tableStyle="#{bean.dtbStyle}"
widgetVar="dtbWGV">
<p:column style="border: none; padding-left: 2px;">
<p:commandButton actionListener="#{bean.removeFromDataTable(rowItem)}"
update="dtb"
style="margin-right: 2px;" icon="fa fa-trash" />
<h:outputText value="#{rowItem.name}" />
</p:column>
<p:column style="border: none; width: 28%;">
<p:spinner suffix="%" min="0" max="100" stepFactor="0.25"
value="#{rowItem.dAux}" size="5" />
</p:column>
</p:dataTable>
The managed bean (ViewScoped):
private ItemClass chosenItem;
private List<ItemClass> chosenItems;
private String dtbStyle;
//getters and setters with no logic inside
//beyond getting and setting the properties
#PostConstruct
public void init(){
if (chosenItems == null) {
chosenItems = new ArrayList<ItemClass>();
}
setDtbStyle("visibility: hidden; width: 320px;");
}
//each time, during the multiple executions,
//the parameter localItem has a different value
public void removeFromDataTable(ItemClass localItem) {
this.chosenItems.remove(localItem);
if(chosenItems.size() == 0) {
setDtbStyle("visibility: hidden; width: 320px;");
}
}
public void addToDataTable(SelectEvent event) {
this.chosenItems.add(this.chosenItem);
setDtbStyle("visibility: visible; width: 320px;");
this.chosenItem = null;
}
Thanks for any clue about what could be happening.
Juliano
After reading here and here, I tried put process="#this" on the remove p:commandButton in the p:dataTable. It has made the trick, but I don`t know excactly how. I've understood that #this tells the server to process just the methods in the actionLinstener of the p:commandButton, ignoring any other actions in other components of the page. Well, the fact that this modification has worked points that the problem is in the overall logic of my page. Actually, I don't know where exactly my mistake is, but as the page is pretty heavy, I'm almost sure there really is a silly mistake of mine somewhere in it.
[1]:Clicking p:commandButton causes the value of p:selectOneMenu being set twice
[2]:Understanding process and update attributes of PrimeFaces
The page.xhtml was modified to:
<p:dataTable id="dtb"
value="#{bean.chosenItems}" var="rowItem"
sortBy="#{rowItem.name}" scrollable="true" scrollHeight="90"
scrollWidth="337" tableStyle="#{bean.dtbStyle}"
widgetVar="dtbWGV">
<p:column style="border: none; padding-left: 2px;">
<p:commandButton actionListener="#{bean.removeFromDataTable(rowItem)}"
update="dtb"
process="#this" <!--solution: adding this attribute-->
style="margin-right: 2px;" icon="fa fa-trash" />
<h:outputText value="#{rowItem.name}" />
</p:column>
<p:column style="border: none; width: 28%;">
<p:spinner suffix="%" min="0" max="100" stepFactor="0.25"
value="#{rowItem.dAux}" size="5" />
</p:column>
</p:dataTable>

JSF Primefaces and ajax listener, button not shown when rendered

I am using JSF and Primefaces to develop a JavaEE application. Each time I press a button(Authenticate), a BUTTON (Button) and a message(Message) must be shown.
The problem is that the message is shown, but not the button. What could I do to show the button?
Here is my code:
ManagedBean IdCertificateManagedBean.java
String m_strRoute;
String m_strMessageRegister;
boolean m_bRegistrationCorrect;
//Getters and Setters
//Constructor
public IdCertificateManagedBean()
{
m_strMessageRegister = "";
m_strRoute = "";
m_bRegistrationCorrect = false;
}
public void authenticateUser()
{
try
{
int a=5;
if (a ==5)
{
m_strMessageRegister = "hello";
m_bRegistrationCorrect = true;
m_strRoute = "/admin/menuadmin";
}
else
{
m_strMessageRegister = "ERROR";
}
}
catch ( Exception e)
{
m_strMessageRegister = "Error";
}
}
}
Facelet
<p:commandButton value="Authenticate">
<p:ajax listener="#{IdCertificateManagedBean.authenticateUser()}" update="Message, Button" />
</p:commandButton>
<h:outputText id="Message" value="#{IdCertificateManagedBean.MessageRegister}" />
<p:commandButton id="Button" value="Go" action="#{IdCertificateManagedBean.route}" rendered=" {IdCertificateManagedBean.registrationCorrect}" />
You must wrap your <h:commandButton /> inside a container as <h:panelGroup /> and then refresh the container.
The problem is that on first page load your button is not rendered so it is not inserted inside the DOM of the page. On page refresh you're trying to refresh it but you can't do it because the button isn't on the page.
A solution could be this
<h:panelGroup layout="block" id="buttonDiv">
<h:commandButton ... />
</h:panelGroup>
and then in your ajax you have to refresh buttonDiv

Struts2 AJAX validation doesn't stay on page

I've been trying for a few days now to make Struts2 AJAX validation work but I can't solve one last problem. I'm using the struts2jquery plugin to asynchronously submit my form:
<div id="result"></div>
<s:form action="RegisterUser" theme="xhtml" method="post">
<s:textfield key="firstname" label="First name" size="35"
required="true" />
<s:textfield key="lastname" label="Last name" size="35"
required="true" />
<s:textfield key="address" label="Address" size="35"
required="true" />
<s:textfield key="phone" label="Phone number" size="35" />
<s:textfield key="username" label="Username" size="35"
required="true" />
<s:password key="password" label="Password" size="35"
required="true" />
<s:textfield key="email" label="E-mail address" size="35"
required="true" />
<sj:submit key="Inregistrare" targets="result" align="right"
button="true" validate="true" onSuccessTopics="notifyRegistration" />
</s:form>
I've included the required scripts:
<script type="text/javascript" src="./js/registerScript.js"></script>
<!-- This files are needed for AJAX Validation of XHTML Forms -->
<script src="${pageContext.request.contextPath}/struts/utils.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/struts/xhtml/validation.js"
type="text/javascript"></script>
and the tag:
<sj:head jqueryui="true" />
The onSuccess handler:
$(document).ready(function(){
$.subscribe('notifyRegistration', function(event,data) {
var registrationStatus = event.originalEvent.data.registrationStatus;
if(registrationStatus == 'SUCCESS'){
alert('Contul dumneavoastra a fost creat cu success!');
window.location.href = "./index.html";
} else {
alert('Contul dumneavoastra nu a putut fi creat. Va rugam incercati din nou.');
}
});
});
My configuration looks like this:
<action name="RegisterUser" class="actions.Register" method="execute">
<interceptor-ref name="jsonValidationWorkflowStack"/>
<result name="input">/pages/Register.jsp</result>
<result type="json"/>
</action>
And the execute method of my action class:
public String execute() throws Exception {
if (isInvalid(getUsername()) || isInvalid(getPassword())
|| isInvalid(getEmail())) {
registrationStatus = REGISTRATION_ERROR;
}
if (registerUser()) {
registrationStatus = REGISTRATION_SUCCESS;
return SUCCESS;
}else {
registrationStatus = REGISTRATION_ERROR;
}
return SUCCESS;
}
The registerUser() method makes the actual insert into the database. The validation XML is called Register-Validation.xml.
The validation works fine - if some fields are not filled in, it shows the error labels without refreshing the page. My problem is that even is the action returns SUCCESS or ERROR, the browser displays the JSON that it sent back on another page, ../Register.action. I have no idea why it doesn't enter my onSuccess handler. I've successfully used AJAX on other forms, the only difference here is that I use the validation xml and the jsonValidationWorkflowStack interceptor. Why is this happening and how can I avoid being redirected? Why doesn't the request reach the onSuccess handler?
Do you have getters for registrationStatus in your Action ?
I would put an alert(event.originalEvent.data.registrationStatus); in your notifyRegistration callback function, just to see what is its value.
By the way, it seems that you have mixed
Struts2-jQuery Plugin AJAX Form Validation with Struts2 XHTML Theme
with
Struts2-jQuery Plugin: Remote Link that handle an JSON Result with an onSuccessTopic
AFAIK (but I've never used this specific kind of validation), the validation should not be handled in execute(), but in validate() or through XML, or with Annotations.
The example in Struts2-jQuery Plugin showcase uses Annotations, but you can easily transform it in XML and try the showcase.
You would have no need to use the javascript function nor the onSuccessTopic at all, following the example.
You can run it in the showcase too, under Forms -> Forms with Validation (but stick to the documentation for the code, because the code in the showcase seems to miss some pieces... for example the validation against "test" password).

Unable to sort a GridView populated by DataView in ASP.NET 2.0 using C#

I am working on extending an ASP.NET 2.0 application using an InterBase database. My experience is in PHP/MySQL, so my familiarity with ASP is currently in the 2-week range, and is pieced together from examining a co-worker's code, the first 90 pages of my ASP book, and Google. In the application, I have an SqlDataSource control connecting to my database and selecting the information I need. Then the results are copied into a DataView where I modify the data in one of the columns, and then I push that DataView to a GridView for output. The issue I'm having is that I cannot sort the GridView at this point. I followed instructions here: http://forums.asp.net/p/956540/1177923.aspx, but to no avail.
Here is the page code:
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="Products" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
ProviderName="<%$ ConnectionStrings:ConnectionString1.ProviderName %>" OnLoad="ProductsDS_Load"
OnSelected="ProductsDS_Selected" DataSourceMode="DataSet">
</asp:SqlDataSource>
<br />
<asp:Label ID="testlabel" runat="server"></asp:Label>
<br />
<asp:Label ID="testlabel2" runat="server"></asp:Label>
<br /><br />
This table lists all 2000+ numbered projects which are at least partially in process.<br />
The Project number link leads to a more detailed view of that project.<br />
<br />
<asp:Label runat="server" ID="numrows"></asp:Label> results returned.
<br />
<asp:GridView ID="ProductsView" runat="server" EnableModelValidation="True"
AutoGenerateColumns="False" CellPadding="4" OnSorting="ProductsView_Sorting"
ForeColor="#333333" GridLines="None" AllowSorting="True">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:HyperLinkField HeaderText="Project" SortExpression="PROJECT"
DataTextField="PROJECT" Target="subweeklyreport" DataNavigateUrlFields="PROJECT"
DataNavigateUrlFormatString="Products.aspx?p={0}" />
<asp:BoundField Visible="false" DataField="PROJECTID" />
<asp:BoundField DataField="PART" HeaderText="Part #"
SortExpression="PART" />
<asp:BoundField DataField="DESCRIPTION" HeaderText="Description"
SortExpression="DESCRIPTION" />
<asp:BoundField DataField="ENGMGR" HeaderText="Eng. Mgr."
SortExpression="ENGMGR" />
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
</asp:GridView>
</div>
</form>
And here is the code behind:
protected void ProductsDS_Load(object sender, EventArgs e)
{
string SQLQuery = Query would go here;
testlabel2.Text = SQLQuery;
Products.SelectCommand = SQLQuery;
Products.DataBind();
DataView dv = (DataView)Products.Select(new DataSourceSelectArguments());
foreach (DataRow dr in dv.Table.Rows)
{
string name = dr["ENGMGR"].ToString();
string[] explode = name.Split(' ');
string newname;
if (explode.Length == 3)
{
newname = explode[2] + ", " + explode[0];
}
else
{
newname = explode[1] + ", " + explode[0];
}
dr["ENGMGR"] = newname;
//testlabel.Text = dr["ENGMGR"].ToString();
}
Products.DataBind();
//ProductsView.DataSourceID = "Products";
ProductsView.DataSource = dv;
ProductsView.DataBind();
ProductsView.Enabled = true;
ProductsView.Visible = true;
}
protected void ProductsDS_Selected(object sender, SqlDataSourceStatusEventArgs e)
{
numrows.Text = e.AffectedRows.ToString();
}
protected void ProductsView_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dataTable = ProductsView.DataSource as DataTable;
if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);
ProductsView.DataSource = dataView;
ProductsView.DataBind();
}
}
private string ConvertSortDirectionToSql(SortDirection sortDirection)
{
string newSortDirection = String.Empty;
switch (sortDirection)
{
case SortDirection.Ascending:
newSortDirection = "ASC";
break;
case SortDirection.Descending:
newSortDirection = "DESC";
break;
}
return newSortDirection;
}
What I think is happening is that whenever the GridView does the postback for the sort, it causes the query to be executed again and overwrite the attempt to sort the existing data in the GridView, but I don't know enough about ASP right now to prevent this behavior. Any help would be much appreciated.
I ended up solving my own problem. I created a session variable to store the dataview between page loads, and checking to see if the dataview is stored before executing the query, and sorting it if it is, and just performing the regular query otherwise. Since I don't expect data to be introduced between the initial page view and the sort, I don't think using a stored copy of the data would be a major issue.

Resources