Submit data-table in JSF / Primefaces? - database

I am working on a web application using jsf/ primefaces, netbeans and tomcat.
I have a datatable with some values loaded in from another table and some editable fields. My question is, after the user has edited this table how do i submit the whole table so it can be stored in a database, in a new table?
<h:form id="form" prependId="false">
<h3>All of your Paddocks</h3>
<p:dataTable var="paddock" value="#{paddock.getfromPaddock()}" editable="true">
<p:ajax event="rowEdit" listener="#{paddock.onRowEdit}" />
<p:ajax event="rowEditCancel" listener="#{paddock.onRowCancel}" />
<p:column headerText="Id">
<h:outputText value="#{paddock.idPaddock}" />
</p:column>
<p:column headerText="Name">
<h:outputText value="#{paddock.name}" />
</p:column>
<p:column headerText="Area">
<h:outputText value="#{paddock.area}" />
</p:column>
<p:column headerText="Enter Grass Weight">
<p:cellEditor>
<f:facet name="output"><h:outputText value="0" /></f:facet>
<f:facet name="input"><p:inputText id="modelInput" value="0" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:32px">
<p:rowEditor />
</p:column>
</p:dataTable>
<h:commandButton value="Log" action="#{paddock.add}" />
</h:form>
Note that the only editable column is the grass column.

First of all, there are two main mistakes which may have undesired side effects:
<h:form ... prependId="false">
Never use prependId. Remove the whole attribute.
<p:dataTable var="paddock" value="#{paddock.getfromPaddock()}">
You should give var a different name than the managed bean. E.g. paddockItem.
As to the concrete question, your other mistake is here:
<p:inputText id="modelInput" value="0" />
You didn't bind the input value to the model. So JSF won't be able to update the model with the submitted values anyway.
Fix it accordingly, e.g.:
<p:inputText id="modelInput" value="#{paddockItem.grass}" />
In the submit method, it'll be right away there in the model.
You should only make absolutely sure that you aren't interacting with the database in the getter method of the <p:dataTable value>, otherwise you will be overwriting the model on every iteration round, hereby basically trashing the submitted values until the last row before the submit method is hit. The strange method name behind the data table value value="#{paddock.getfromPaddock()}" namely suggests that you're doing that. If it were a real property, the average starter would just have used value="#{paddock.fromPaddock}" or so.
See also:
How and when should I load the model from database for h:dataTable

Related

I can't change range and/or default values in DevExpress Dashboard

I have a page where users register and can make their personal diet plan etc.
I am trying to make some graphs with built-in VS dashboards.
I am using VS 2015 and SQL Server Management Studio 15.0.18206.0 if that matters.
My problems are the following:
Automatic (SUM)
Dashboard values default to SUM function, which I am not able to change, as you see in the first picture, but I kind of managed to solve this problem with the help of SQL (SELECT DISTINCT, SELECT TOP(1) etc.)
Automatic (SUM)
Default year count
When I am trying to make a dashboard to show track of user's vitals and activity, which is the core of my statistics, time defaults to YEAR and the result end up like the second picture.
Default year count
There is nothing I can do to change these and I just made irrelevant graphs to fill the page, but it's a shame because I planned to make a lot of graphs with the table you see in the third picture.
User History table
If it helps, the XML code generated from the last dashboard is this:
<?xml version="1.0" encoding="utf-8"?>
<Dashboard>
<Title Text="YearDashBoard" />
<DataSources>
<SqlDataSource ComponentName="DataSource1">
<Name>UserHistory1</Name>
<Connection Name="foodConnectionString" FromAppConfig="true" />
<Query Type="SelectQuery" Name="UserHistory1" Distinct="true">
<Tables>
<Table Name="UserHistory" />
</Tables>
<Columns>
<Column Table="UserHistory" Name="CaloriesDate" />
<Column Table="UserHistory" Name="DailyCalories" />
<Column Table="UserHistory" Name="UserID" />
</Columns>
<Filter>[UserHistory.UserID] = 17</Filter>
</Query>
<ConnectionOptions CloseConnection="true" CommandTimeout="0" />
</SqlDataSource>
</DataSources>
<Items>
<Chart ComponentName="chartDashboardItem1" Name="Chart 1" DataSource="DataSource1" DataMember="UserHistory1">
<DataItems>
<Measure DataMember="DailyCalories" DefaultId="DataItem0" />
<Dimension DataMember="CaloriesDate" DefaultId="DataItem1" />
</DataItems>
<Arguments>
<Argument DefaultId="DataItem1" />
</Arguments>
<Panes>
<Pane Name="Pane 1">
<Series>
<Simple>
<Value DefaultId="DataItem0" />
</Simple>
</Series>
</Pane>
</Panes>
</Chart>
</Items>
<LayoutTree>
<LayoutGroup Weight="100">
<LayoutItem DashboardItem="chartDashboardItem1" Weight="100" />
</LayoutGroup>
</LayoutTree>
</Dashboard>
Finally, with the help of DevExpress technical team, I found out that the whole time there was an invisible scroll bar, but you had to mouse over it (!) while being on the "BINDING" tab of the menu.

How to publish additional postgis raster layer attributes in geoserver?

i was wondering if any of You can help me with my problem. I'm storing some rasters in Postgis database. Each raster is in its own table and besides 'rid' and 'rast' columns, I manualy added other columns to store raster attributes such as 'metadata'...
I have successfully imported rasters in geoserver using ImageMosaic JDBC and in Layers Preview (OpenLayers) I can see rasters and use getFeatureInfo function, but the problem is that function getFeatureInfo returns table with correct pixel value , 'rid' field is empty (only table header apears) and no other attribute is shown (not even attribute header in table). I'm using default geoserver method for layer preview function.
mapping.postgis.xml.inc file
<!-- possible values: universal,postgis,db2,mysql,oracle -->
<spatialExtension name="pgraster"/>
<mapping>
<masterTable name="mosaic" >
<coverageNameAttribute name="name"/>
<maxXAttribute name="maxx"/>
<maxYAttribute name="maxy"/>
<minXAttribute name="minx"/>
<minYAttribute name="miny"/>
<resXAttribute name="resx"/>
<resYAttribute name="resy"/>
<tileTableNameAtribute name="tiletable" />
</masterTable>
<tileTable>
<blobAttributeName name="rast" />
<keyAttributeName name="rid" />
<textAttributeName name="metadata" />
</tileTable>
</mapping>
connect.postgis.xml.inc
<connect>
<!-- value DBCP or JNDI -->
<dstype value="DBCP"/>
<!-- <jndiReferenceName value=""/> -->
<username value="postgres" />
<password value="postgres" />
<jdbcUrl value="jdbc:postgresql://localhost:5432/web_kartografija" />
<driverClassName value="org.postgresql.Driver"/>
<maxActive value="10"/>
<maxIdle value="0"/>
</connect>
layer.postgis.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE ImageMosaicJDBCConfig [
<!ENTITY mapping PUBLIC "mapping" "mapping.postgis.xml.inc">
<!ENTITY connect PUBLIC "connect" "connect.postgis.xml.inc">]>
<config version="1.0">
<coverageName name="jan"/> <!-- Name of the table in database -->
<coordsys name="EPSG:4326"/>
<!-- interpolation 1 = nearest neighbour, 2 = bilinear, 3 = bicubic -->
<scaleop interpolation="1"/>
<verify cardinality="false"/>
&mapping;
&connect;
</config>
I tried to include <textAttributeName name="metadata" /> as a column name where aditional data is stored, but still no effect. Can anobudy help me with this problem ? Thanks in advance !

gridCells are overlapping in Oracle ADF

I have a grisRow & within that I have 2 gridCell
In the first one, a description is displayed.
In the second cell, an action icon is displayed.
But the description is touching or overlapping with the icon.
How can I avoid this.
<af:gridCell width="50%" id="gc2" valign="top"
halign="start" marginStart="4px" marginEnd="10px">
<af:panelFormLayout id="pfl2">
<af:link id="ot11" text="#{row.name}"
clientComponent="true"
partialSubmit="true" styleClass="list-hdr-fields"
shortDesc="#{userinterfaceBundle.MANAGE_ROLES_LABEL}">
<af:clientAttribute name="uId"
value="#{row.name}"/>
<af:showPopupBehavior popupId="::manageRolesPopup"
triggerType="click"/>
</af:link>
<af:outputText value="#{row.description}"
shortDesc="#{userinterfaceBundle.DESCRIPTION_LABEL}"
id="ot12" />
<f:facet name="footer"/>
</af:panelFormLayout>
</af:gridCell>
<af:gridCell width="25%" id="gc3" valign="middle"
halign="end" marginStart="40px">
<af:panelGroupLayout styleClass="lv-row-col-right"
id="pgl2">
<af:panelGroupLayout styleClass="lv-row-col"
id="pgl16">
<af:link id="l4"
icon="/oracle/ics/webconsole/view/images/func_preferences-new_16_ena.png"
disabledIcon="/oracle/ics/webconsole/view/images/func_preferences-new_16_dis.png"
hoverIcon="/oracle/ics/webconsole/view/images/func_preferences-new_16_hov.png"
depressedIcon="/oracle/ics/webconsole/view/images/func_preferences-new_16_act.png"
iconPosition="trailing"
shortDesc="#{userinterfaceBundle.ACTIONS_LABEL}">
</af:link>
</af:panelGroupLayout>
</af:panelGroupLayout>
</af:gridCell>
</af:gridRow>
Try using af:panelGroupLayout with layout="horizontal" instead of af:panelFormLayout
add an af:spacer next to the component you need space next to and surround with panelGroup layout horizontal.
http://jdevadf.oracle.com/adf-richclient-demo/docs/tagdoc/af_spacer.html
According to the Geometry Management of <af:gridCell>:
Beware that if you attempt to use width="auto", halign="center",
halign="end" in conjunction with cell content that uses unstable,
percentage-based widths, you may experience different results in
different browsers. If you wish to use these settings, be sure to
constraint the width of that cell content.
Possible Workaround: instead of halign="end", change it to halign="stretch" (source).

<h:commandLink> action not invoke if include with <ui:include>

If I place inside an include file, the action will not call back bean.
Main File:
<h:form id="ifLogin">
<h:panelGrid
rendered="#{userSession.isLogin}"
columns="2" columnClasses="columnAlignLeft, columnAlignRight"
border="0" cellpadding="0">
<ui:include src="\test.xhtml" />
...
</h:panelGrid>
</h:form>
Include file (test.xhtml)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<h:panelGrid border="0" columns="4">
<h:graphicImage value="#{msg.urlImageHome}"
style="height:26px;width:26px;" />
<f:subview>
<h:commandLink value="#{msg.home}" style="font-size: small;" immediate="true"
action="#{pageNavigationBean.updateCeaAppName}">
<f:param name="requestName" value="CEA_MAIN_PAGE" />
<f:param name="ceaAppName" value="" />
</h:commandLink>
</f:subview>
</h:panelGrid>
</ui:composition>
The workaround is take out include file, directly place the code to main file as below:
Main file (without using include)
<h:form id="ifLogin">
<h:panelGrid
rendered="#{userSession.isLogin}"
columns="2" columnClasses="columnAlignLeft, columnAlignRight"
border="0" cellpadding="0">
<h:panelGrid border="0" columns="4">
<h:graphicImage value="#{msg.urlImageHome}"
style="height:26px;width:26px;" />
<f:subview>
<h:commandLink value="#{msg.home}" style="font-size: small;" immediate="true"
action="#{pageNavigationBean.updateCeaAppName}">
<f:param name="requestName" value="CEA_MAIN_PAGE" />
<f:param name="ceaAppName" value="" />
</h:commandLink>
</f:subview>
</h:panelGrid>
...
</h:panelGrid>
</h:form>
I use richface 4.3.1 Odd is this problem not happen when I run from local GAE. After deploy online to GAE, problem occour (i.e if using include then action will not trigger.
Is that a bug in jsf? or richface implementation or GAE? Any help?
Problem identify
It is not cause by using <ui:include>
The problem came out when the include file is dynamic generate from back bean, for example:
<ui:include src="#{pageNavigationBean.appDropDownMenuUrl}" />
If explicit mention the url, it work, for example:
<ui:include src="\test.xhtml" />
Well, if running from my local GAE, both way are working but when deploy online, I need use explicit location instead generate from bean. May be that is due to GAE problem where state is save at Client side (javax.faces.STATE_SAVING_METHOD).
I can't reproduce the problem with exactly the same included code (test.xhtml), but here are some recommendation:
Escape '>' characters (replace >>> by >>>)
Specify id attribute for f:subview (it is required according to tld)
Change backslash ('\') to slash ('/'). So inclusion would be <ui:include src="/test.xhtml" />

How to avoid validation of input items within af table and javascript

I developed a form which includes table and commandButton. Some input items are required. I want them to validate while just button pressed.
And everything was ok, this scenario was working well. But when table presents only one row, selecting row does not work. See alsa plz: https://forums.oracle.com/forums/thread.jspa?threadID=960512&start=0&tstart=0 --> might be 9th post
I applied to my jsff the solution which is told in above link. It works previous issue but this time, javascript caused another problem that is inconsistent validation. As i understood java script overrides af table immediate="true" property. plz see : http://www4.picturepush.com/photo/a/11897217/640/11897217.png
How can i resolve that? Any suggestion?
Plz help me
Thanks in advance
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:af="http://xmlns.oracle.com/adf/faces/rich"
xmlns:trh="http://myfaces.apache.org/trinidad/html"
xmlns:f="http://java.sun.com/jsf/core">
<trh:script>
function tableLoad(event)
{
AdfCustomEvent.queue(event.getSource(), "refreshTables",
{
},
true);
event.cancel();
}
</trh:script>
......
<af:table var="row" rowBandingInterval="1" id="entityT"
value="#{pageFlowScope.incomingPaperworkBean.baseRowCollection}"
partialTriggers="::cb_incPaperDef_commit ::cb_incPaperDef_filter"
rowSelection="single" columnBandingInterval="0"
disableColumnReordering="true" columnStretching="column:c3"
styleClass="AFStretchWidth" autoHeightRows="20"
contentDelivery="immediate" immediate="true"
binding="#{pageFlowScope.incomingPaperworkBean.richTable}">
<af:clientListener method="tableLoad" type="click"/>
<af:serverListener type="refreshTables"
method="#{pageFlowScope.incomingPaperworkBean.refreshTables}"/>
<af:column id="c5" width="105">
<af:inputText id="registrationText"
value="#{row.baseEntity.registrationNumber.registrationNumber}"
required="true" readOnly="true" autoSubmit="true"
disabled="true"/>
<f:facet name="header">
<af:panelGroupLayout id="panelGroupLayout1" layout="vertical">
<af:inputText id="filterRegistrationNumber"
value="#{pageFlowScope.incomingPaperworkBean.filterTemplate.incomingPaperwork.registrationNumber.registrationNumber}"
simple="true" autoSubmit="true"/>
<af:spacer width="10" height="10" id="spacer1"/>
<af:outputText value="Kayit Numarasi" id="outputText6"/>
</af:panelGroupLayout>
</f:facet>
</af:column>
......
Set the immediate parameter on the component clicking on which fires the validation.

Resources