Недавно я столкнулся с действительно странной проблемой. Это выглядит следующим образом:
На странице сохранения типичного рабочего процесса CRUD нажатие кнопки h: commandButton для вызова метода сохранения в компоненте конечного объекта не работает все время. Иногда это работает так, как я ожидал, завершив метод, который я направляю в боб. В других случаях он просто создает новый Бин без входа в режим обновления, не говоря уже о том, что он входит в метод бина. В консоли не отображаются сообщения об ошибках, только некоторые подозрительные операторы, такие как: [component] Нет типа рендерера для компонента j_id26 и т. Д.
Я попытался решить эту проблему, присвоив всем тегам JSF html идентификатор. Тем не менее, это выглядит напрасно. Даже я не могу воспроизвести с фиксированной манерой. Слишком случайно, чтобы понять фундаментальные принципы ошибок.
Потому что источник страницы немного огромен. Позвольте мне подтвердить, есть ли у вас, ребята, похожие проблемы, и я сделаю еще один шаг, чтобы показать больше подсказок, в зависимости от того, что нужно.
Заранее спасибо.
Код выглядит следующим образом:
1.graphtemplate.xhtml
........
<table>
<tr>
<td id="tdBtnSave"><h:commandButton id="invisibleBtnSave"
action="#{graphTemplate.save}" style="display: none">
</h:commandButton>
<button type="button" dojoType="dijit.form.Button" id="step5Save">SAVE</button>
</td>
<td>
<button type="button" dojoType="dijit.form.Button" id="step5Cancel">CANCEL</button>
</td>
</tr>
</table>
<p />
.............
2.GraphTemplateBean.java
/**
*
* @author Freeman Bo Ye
*
*/
public class GraphTemplateBean extends ThinBeanBase {
public Integer id = null;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
/*
* y, x axis data (step 1)
*/
private List<String> yAxes = new ArrayList<String>(); // y axes
private Integer yScaleType = null; // y axis scale type
private Boolean yScaleIsAuto = null; // y axis scale is auto
private Double yCustomNumStart = null; // y custom start
private Double yCustomNumEnd = null; // y custom end
private Double yCustomNumTicMarks = null; // y custom tic marks
private String xAxis = null; // x axis
private Integer xScaleType = null; // x axis scale type
private Boolean xScaleIsAuto = null; // x axis scale is auto
private Date xCustomDateStart = null; // x axis custom date start
private Double xCustomNumStart = null; // x axis custom number start
private Date xCustomDateEnd = null; // x axis custom date end
private Double xCustomNumEnd = null; // x axis custom number end
private Integer xCustomDateTicMarks = null; // x custom date tic marks
private Double xCustomNumTicMarks = null; // x custom number tic marks
/*
* graph titles (step 2)
*/
private List<String> graphTitles = new ArrayList<String>(); // graph titles
private String graphCustomTitle = null; // graph custom title
private Integer graphTitleFontSize = null; // graph title font size
private Color graphTitleColor = null; // graph title color
private List<Integer> graphTitleStyles = new ArrayList<Integer>(); // graph title styles
private Boolean isMultiLines = null; // is multiple lines
private String yTitle = null; // y title
private String yCustomTitle = null; // y custom title
private Integer yTitleFontSize = null; // y title font size
private Color yTitleColor = null; // y title color
private List<Integer> yTitleStyles = new ArrayList<Integer>(); // y title styles
private String xTitle = null; // x title
private String xCustomTitle = null; // x custom title
private Integer xTitleFontSize = null; // x title font size
private Color xTitleColor = null; // x title color
private List<Integer> xTitleStyles = new ArrayList<Integer>(); // x title styles
/*
* line styles (step 3)
*/
private List<LineStyle> lineStyles = new ArrayList<LineStyle>(); // line styles
/*
* define legend (step 4)
*/
private Boolean isShowUserLegend = null;
private List<String> legendTitles = new ArrayList<String>();
private Integer userLegendFontSize = null;
private Color userLegendColor = null;
private List<Integer> userLegendStyles = new ArrayList<Integer>();
private Boolean isShowDataLegend = null;
private Integer dataLegendFontSize = null;
private Color dataLegendColor = null;
private List<Integer> dataLegendStyles = new ArrayList<Integer>();
/*
* name and extra properties (step 5)
*/
private String name = null; // graph template name
private List<Integer> extraProps = new ArrayList<Integer>(); // graph template's extra properties
public GraphTemplateBean() {
logger.debug("new graph template bean request......");
for (SelectItem selectItem : getAllYAxes()) {
LineStyle lineStyle = new LineStyle();
lineStyle.setyAxis(selectItem.getLabel());
lineStyles.add(lineStyle);
}
logger.info("GraphTemplateBean is created.");
}
..............
/**
* Get creating type from scratch or saved graph template.
*
* @return from scratch or saved
*/
public List<SelectItem> getFromScratchOrSaved() {
List<SelectItem> result = new ArrayList<SelectItem>();
result.add(new SelectItem(true, "Create new graph from scratch"));
result.add(new SelectItem(false, "Start with saved graph:"));
return result;
}
/**
* All graph templates
*
* @return all graph templates
* @throws GraphServiceException
*/
public List<SelectItem> getAllGraphTemplates() throws GraphServiceException {
List<SelectItem> result = new ArrayList<SelectItem>();
GraphService gs = GraphServiceFactory.getInstance(getUser());
List<MyTemplate> graphTemplates = gs.listMyTemplate();
for (MyTemplate graphTemplate : graphTemplates) {
result.add(new SelectItem(graphTemplate.getId(), graphTemplate.getName()));
}
return result;
}
/**
* all y axes.
*
* @return all y axes
*/
public List<SelectItem> getAllYAxes() {
List<SelectItem> result = new ArrayList<SelectItem>();
result.add(new SelectItem("Oil (bbl)", "Oil (bbl)"));
result.add(new SelectItem("Gas (mcf)", "Gas (mcf)"));
result.add(new SelectItem("Water (bbl)", "Water (bbl)"));
result.add(new SelectItem("Injection", "Injection"));
result.add(new SelectItem("Historical Well Count", "Historical Well Count"));
result.add(new SelectItem("Cumulative Oil (bbl)", "Cumulative Oil (bbl)"));
result.add(new SelectItem("Cumulative Gas (mcf)", "Cumulative Gas (mcf)"));
result.add(new SelectItem("Cumulative Water (bbl)", "Cumulative Water (bbl)"));
result.add(new SelectItem("Cumulative Injection", "Cumulative Injection"));
result.add(new SelectItem("Annual Oil (bbl)", "Annual Oil (bbl)"));
result.add(new SelectItem("Annual Gas (mcf)", "Annual Gas (mcf)"));
result.add(new SelectItem("Annual Water (bbl)", "Annual Water (bbl)"));
result.add(new SelectItem("Annual Injection", "Annual Injection"));
result.add(new SelectItem("Water Cut", "Water Cut"));
result.add(new SelectItem("Oil Cut", "Oil Cut"));
result.add(new SelectItem("Gas/Oil Ratio", "Gas/Oil Ratio"));
result.add(new SelectItem("Yield", "Yield"));
result.add(new SelectItem("Water/Oil Ratio", "Water/Oil Ratio"));
result.add(new SelectItem("Oil/Water Ratio", "Oil/Water Ratio"));
result.add(new SelectItem("Water/Gas Ratio", "Water/Gas Ratio"));
result.add(new SelectItem("Oil/Injection Ratio", "Oil/Injection Ratio"));
result.add(new SelectItem("Injection/Oil Ratio", "Injection/Oil Ratio"));
result.add(new SelectItem("Injection/(Oil+Water)", "Injection/(Oil+Water)"));
result.add(new SelectItem("(Oil+Water)/Injection", "(Oil+Water)/Injection"));
result.add(new SelectItem("Injection/Gas Ratio", "Injection/Gas Ratio"));
result.add(new SelectItem("Gas/Injection Ratio", "Gas/Injection Ratio"));
result.add(new SelectItem("Bottom Hole Pressure", "Bottom Hole Pressure"));
result.add(new SelectItem("Flowing Pressure", "Flowing Pressure"));
result.add(new SelectItem("Tubing Pressure", "Tubing Pressure"));
result.add(new SelectItem("BHP/Z Pressure", "BHP/Z Pressure"));
return result;
}
/**
* all y, x axis scales.
*
* @return
*/
public List<SelectItem> getAllScaleTypes() {
List<SelectItem> result = new ArrayList<SelectItem>();
result.add(new SelectItem(0, "Linear"));
result.add(new SelectItem(1, "Logarithmic"));
return result;
}
/**
* all y, x axis scale configurations.
*
* @return
*/
public List<SelectItem> getScaleAutoOrCustom() {
List<SelectItem> result = new ArrayList<SelectItem>();
result.add(new SelectItem(true, "Automatically scale to fit data"));
result.add(new SelectItem(false, "Custom scale"));
return result;
}
/**
* all x axes.
*
* @return all x axes
*/
public List<SelectItem> getAllXAxes() {
List<SelectItem> result = new ArrayList<SelectItem>();
result.add(new SelectItem("Time", "Time"));
result.add(new SelectItem("Cumulative Oil (bbl)", "Cumulative Oil (bbl)"));
result.add(new SelectItem("Cumulative Gas (mcf)", "Cumulative Gas (mcf)"));
result.add(new SelectItem("Cumulative Water (bbl)", "Cumulative Water (bbl)"));
result.add(new SelectItem("Cumulative Injection", "Cumulative Injection"));
return result;
}
/**
* all graph titles.
*
* @return all graph titles
*/
public List<SelectItem> getAllGraphTitles() {
List<SelectItem> result = new ArrayList<SelectItem>();
result.add(new SelectItem("Custom", "Custom"));
result.add(new SelectItem("Production ID", "Production ID"));
result.add(new SelectItem("Lease Name", "Lease Name"));
result.add(new SelectItem("Well Number", "Well Number"));
result.add(new SelectItem("API Number", "API Number"));
result.add(new SelectItem("API Unique Number", "API Unique Number"));
result.add(new SelectItem("Operator", "Operator"));
result.add(new SelectItem("First Production Date", "First Production Date"));
result.add(new SelectItem("Last Production Date", "Last Production Date"));
result.add(new SelectItem("Lease Type", "Lease Type"));
result.add(new SelectItem("Lease Status", "Lease Status"));
result.add(new SelectItem("Cumulative Oil", "Cumulative Oil"));
result.add(new SelectItem("Cumulative Gas", "Cumulative Gas"));
result.add(new SelectItem("Cumulative Water", "Cumulative Water"));
result.add(new SelectItem("Cumulative Injection", "Cumulative Injection"));
result.add(new SelectItem("State", "State"));
result.add(new SelectItem("County", "County"));
result.add(new SelectItem("Field", "Field"));
result.add(new SelectItem("Reservoir", "Reservoir"));
result.add(new SelectItem("Producing Zone", "Producing Zone"));
result.add(new SelectItem("Location", "Location"));
return result;
}
/**
* all font sizes.
*
* @return all font sizes
*/
public List<SelectItem> getAllFontSizes() {
List<SelectItem> result = new ArrayList<SelectItem>();
result.add(new SelectItem(8, "8px"));
result.add(new SelectItem(10, "10px"));
result.add(new SelectItem(12, "12px"));
result.add(new SelectItem(14, "14px"));
result.add(new SelectItem(16, "16px"));
result.add(new SelectItem(18, "18px"));
result.add(new SelectItem(20, "20px"));
result.add(new SelectItem(25, "25px"));
result.add(new SelectItem(30, "30px"));
result.add(new SelectItem(35, "35px"));
result.add(new SelectItem(40, "40px"));
result.add(new SelectItem(45, "45px"));
return result;
}
/**
* all styles.
*
* @return all styles
*/
public List<SelectItem> getAllStyles() {
List<SelectItem> result = new ArrayList<SelectItem>();
result.add(new SelectItem(0, "Bold"));
result.add(new SelectItem(1, "Italic"));
return result;
}
/**
* all y titles.
*
* @return all y titles
*/
public List<SelectItem> getAllYTitles() {
List<SelectItem> result = new ArrayList<SelectItem>();
if (yAxes.size() == 0)
result.addAll(getAllYAxes());
else {
for (String yAxis : yAxes) {
result.add(new SelectItem(yAxis, yAxis));
}
}
result.add(new SelectItem("Custom Title", "< Custom Title >"));
return result;
}
/**
* all x titles.
*
* @return all x titles
*/
public List<SelectItem> getAllXTitles() {
List<SelectItem> result = new ArrayList<SelectItem>();
if (xAxis == null)
result.addAll(getAllXAxes());
else
result.add(new SelectItem(xAxis, xAxis));
result.add(new SelectItem("Custom Title", "< Custom Title >"));
return result;
}
/**
* all line scales.
*
* @return all line scales
*/
public List<SelectItem> getAllLineScales() {
List<SelectItem> result = new ArrayList<SelectItem>();
result.add(new SelectItem(0.0329, "Daily"));
result.add(new SelectItem(0.01, "X 0.01"));
result.add(new SelectItem(0.1, "X 0.1"));
result.add(new SelectItem(1.0, "X 1"));
result.add(new SelectItem(10.0, "X 10"));
result.add(new SelectItem(100.0, "X 100"));
result.add(new SelectItem(1000.0, "X 1,000"));
result.add(new SelectItem(10000.0, "X 10,000"));
result.add(new SelectItem(100000.0, "X 100,000"));
return result;
}
/**
* all label positions.
*
* @return all label positions
*/
public List<SelectItem> getAllLabelPositions() {
List<SelectItem> result = new ArrayList<SelectItem>();
result.add(new SelectItem(0, "Line Start"));
result.add(new SelectItem(1, "Line End"));
return result;
}
/**
* all legend titles.
*
* @return all legend titles
*/
public List<SelectItem> getAllLegendTitles() {
List<SelectItem> result = getAllGraphTitles();
result.remove(0);
return result;
}
/**
* all extra properties.
*
* @return all extra properties
*/
public List<SelectItem> getAllExtraProps() {
List<SelectItem> result = new ArrayList<SelectItem>();
result.add(new SelectItem(0, "Make this the default graph on the view Records page"));
result.add(new SelectItem(1, "Allow other people in my company to use this graph"));
return result;
}
private List<Integer> convertStylesAsList(int nStyles) {
List<Integer> result = new ArrayList<Integer>();
switch (nStyles) {
case 0:
break;
case 1:
result.add(0);
break;
case 4:
result.add(1);
break;
case 5:
result.add(0);
result.add(1);
break;
default:
throw new IllegalStateException(
"The title sytle is not correct configured, probably the underlying graph template file is corrupted!");
}
return result;
}
private int convertStylesAsInteger(List<Integer> listStyle) {
assert (listStyle != null);
int result = 0;
for (Integer style : listStyle) {
switch (style) {
case 0:
result += 1;
break;
case 1:
result += 4;
break;
default:
throw new UnsupportedOperationException("Not implemented yet");
}
}
return result;
}
private List<Integer> convertLabelPositionsAsList(int nLabelPositions) {
List<Integer> result = new ArrayList<Integer>();
switch (nLabelPositions) {
case 0:
break;
case 1:
result.add(0);
break;
case 2:
result.add(1);
break;
case 3:
result.add(0);
result.add(1);
break;
default:
throw new IllegalStateException(
"The line sytle's lable positions is not correct configured, probably the underlying graph template file is corrupted!");
}
return result;
}
private int convertLabelPositionsAsInteger(List<Integer> listLabelPosition) {
assert (listLabelPosition != null);
int result = 0;
for (Integer labelPosition : listLabelPosition) {
switch (labelPosition) {
case 0:
result += 1;
break;
case 1:
result += 2;
break;
default:
throw new UnsupportedOperationException("Not implemented yet");
}
}
return result;
}
public String create() throws GraphServiceException {
logger.debug("create graph template......");
/*
* y, x axis data (step 1)
*/
yAxes.add("Oil (bbl)");
yScaleType = 1;
yScaleIsAuto = true;
xAxis = "Time";
xScaleType = 0;
xScaleIsAuto = true;
/*
* graph titles (step 2)
*/
graphTitles.add("Lease Name");
graphTitles.add("Well Number");
graphTitles.add("API Number");
graphTitleFontSize = 10;
graphTitleColor = Color.BLACK;
isMultiLines = false;
yTitleFontSize = 10;
yTitleColor = Color.BLACK;
xTitleFontSize = 10;
xTitleColor = Color.BLACK;
/*
* line styles (step 3)
*/
for (LineStyle lineStyle : lineStyles) {
lineStyle.setInUse(yAxes.contains(lineStyle.getyAxis()) ? true : false);
lineStyle.setLineStyle(0);
lineStyle.setLineScale(1.0);
if (lineStyle.getyAxis().endsWith("Oil (bbl)"))
lineStyle.setColor(Color.GREEN);
else if (lineStyle.getyAxis().endsWith("Gas (mcf)"))
lineStyle.setColor(Color.RED);
else if (lineStyle.getyAxis().endsWith("Water (bbl)"))
lineStyle.setColor(Color.BLUE);
else if ("Water/Oil Ratio".equals(lineStyle.getyAxis()))
lineStyle.setColor(Color.WHITE);
else
lineStyle.setColor(Color.BLACK);
lineStyle.setLabelPositions(new ArrayList<Integer>());
}
/*
* Define Legend (step 4)
*/
isShowUserLegend = false;
legendTitles.addAll(graphTitles);
userLegendFontSize = 10;
userLegendColor = Color.BLACK;
isShowDataLegend = false;
dataLegendFontSize = 10;
dataLegendColor = Color.BLACK;
/*
* name and extra properties (step 5)
*/
int max = 0;
for (SelectItem selectItem : getAllGraphTemplates()) {
if (selectItem.getLabel().indexOf("My Graph Template ") != -1
&& patInteger.matcher(selectItem.getLabel().substring(18)).matches()) {
int sequence = Integer.parseInt(selectItem.getLabel().substring(18));
if (sequence > max)
max = sequence;
}
}
name = "My Graph Template " + (max + 1);
return "create";
}
public String save() throws GraphServiceException {
logger.debug("save graph template......");
GraphService gs = GraphServiceFactory.getInstance(getUser());
GraphConfiguration graphConfiguration = null;
MyTemplate myTemplate = null;
if(id==0)
id= null;
if (id != null) {
gs.setTemplateId(id);
gs.loadGraphTemplate();
}
graphConfiguration = new GraphConfiguration();
/*
* y, x axis data (step 1)
*/
for (int i = 0; i < yAxes.size(); i++) {
GraphSeries graphSeries = new GraphSeries();
graphSeries.setId(i + 1);
AxisInfo yAxisInfo = new AxisInfo();
yAxisInfo.setName(yAxes.get(i));
yAxisInfo.setType(yScaleType);
yAxisInfo.setAutoScale(yScaleIsAuto);
if (!yScaleIsAuto) {
yAxisInfo.setStartValue(yCustomNumStart.toString());
yAxisInfo.setEndValue(yCustomNumEnd.toString());
yAxisInfo.setTicks(yCustomNumTicMarks);
}
graphSeries.setY(yAxisInfo);
AxisInfo xAxisInfo = new AxisInfo();
xAxisInfo.setName(xAxis);
xAxisInfo.setType(xScaleType);
xAxisInfo.setAutoScale(xScaleIsAuto);
if (!xScaleIsAuto) {
boolean isTime = "Time".equals(xAxis);
xAxisInfo.setStartValue(isTime ? yearFormat.format(xCustomDateStart) : xCustomNumStart.toString());
xAxisInfo.setEndValue(isTime ? yearFormat.format(xCustomDateEnd) : xCustomNumEnd.toString());
xAxisInfo.setTicks(isTime ? xCustomDateTicMarks : xCustomNumTicMarks);
}
graphSeries.setX(xAxisInfo);
graphConfiguration.addSeries(graphSeries);
}
/*
* graph titles (step 2)
*/
GraphTitle graphTitle = new GraphTitle();
for (String tmp : graphTitles)
graphTitle.addStandardData(!"Custom".equals(tmp) ? tmp : graphCustomTitle);
graphTitle.setSize(graphTitleFontSize);
graphTitle.setColor(colorConverter.getAsString(null, null, graphTitleColor));
graphTitle.setStyle(convertStylesAsInteger(graphTitleStyles));
graphTitle.setMultiline(isMultiLines);
AxisLabel yAxisLabel = new AxisLabel();
yAxisLabel.setName(!"Custom Title".equals(yTitle) ? yTitle : yCustomTitle);
yAxisLabel.setSize(yTitleFontSize);
yAxisLabel.setColor(colorConverter.getAsString(null, null, yTitleColor));
yAxisLabel.setStyle(convertStylesAsInteger(yTitleStyles));
AxisLabel xAxisLabel = new AxisLabel();
xAxisLabel.setName(!"Custom Title".equals(xTitle) ? xTitle : xCustomTitle);
xAxisLabel.setSize(xTitleFontSize);
xAxisLabel.setColor(colorConverter.getAsString(null, null, xTitleColor));
xAxisLabel.setStyle(convertStylesAsInteger(xTitleStyles));
graphConfiguration.setTitle(graphTitle);
graphConfiguration.setYLabel(yAxisLabel);
graphConfiguration.setXLabel(xAxisLabel);
/*
* line styles (step 3)
*/
for (int i = 0; i < lineStyles.size(); i++) {
LineStyle lineStyle = lineStyles.get(i);
if (lineStyle.getInUse()) {
Line line = new Line();
line.setSeries(i + 1);
line.setStyle(lineStyle.getLineStyle());
line.setScale(lineStyle.getLineScale());
line.setColor(colorConverter.getAsString(null, null, lineStyle.getColor()));
line.setLabel(convertLabelPositionsAsInteger(lineStyle.getLabelPositions()));
line.setLegend(true);
graphConfiguration.addLine(line);
}
}
/*
* define legend (step 4)
*/
if (isShowUserLegend) {
UserLegend userLegend = new UserLegend();
for (String legendTitle : legendTitles) {
userLegend.addStandardData(legendTitle);
}
userLegend.setSize(userLegendFontSize);
userLegend.setColor(colorConverter.getAsString(null, null, userLegendColor));
userLegend.setStyle(convertStylesAsInteger(userLegendStyles));
graphConfiguration.setUserLegend(userLegend);
}
if (isShowDataLegend) {
DataLegend dataLegend = new DataLegend();
dataLegend.setSize(dataLegendFontSize);
dataLegend.setColor(colorConverter.getAsString(null, null, dataLegendColor));
dataLegend.setStyle(convertStylesAsInteger(dataLegendStyles));
graphConfiguration.setDataLegend(dataLegend);
}
/*
* name and extra properties (step 5)
*/
myTemplate = (id == null ? new MyTemplate() : gs.getTemplate());
myTemplate.setName(name);
myTemplate.setPath(getUser().getHomeDirectory() + GraphConfiguration.PATH + name);
for (Integer extraProp : extraProps) {
switch (extraProp) {
case 0:
myTemplate.setDefault(true);
break;
case 1:
myTemplate.setPublic(MyTemplate.PUBLIC);
break;
default:
throw new UnsupportedOperationException("Not implemented yet!");
}
}
// save...
if (id == null) {
logger.info("new graph template......");
gs.insertMyTemplate(graphConfiguration, myTemplate);
} else {
logger.info("update graph template(id) " + id);
gs.updateMyTemplate(graphConfiguration, myTemplate);
}
return "success";
}
....................